﻿<template>
  <a-modal
    title="编辑药品目录管理"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['sysClass']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugId']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugCode']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugName']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['toxiProperty']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugForm']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugUsage']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugInputCode']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugInputCodeWb']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugSpec']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['storeUnit']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['firmId']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['tradePrice']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['retailPrice']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['outpUnit']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['outpMod']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['inpUnit']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['inpMod']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['leastPack']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['leastUnit']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['leastDose']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['classOnOutpRcpt']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['classOnInpRcpt']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['classOnReckoning']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['subjCode']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['classOnMr']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['forignCode']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['feeTypeMask']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['operator']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择" v-decorator="['enterDate']" @change="onChangeenterDate"/>
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['performedByCode']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['performedByName']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['remark']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['back1']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['back2']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['inPrice']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['doseUnit']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['siLevel']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['siCode']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugProperty']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['prescriptionFlag']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugLimit']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['collisionFlag']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugAlias']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugEng']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['bidFlag']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['execLevel']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugType']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['siRate']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['limitDays']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['passCode']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugType1']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugType2']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugType3']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugType4']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugType5']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['dosage']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['frequency']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['yh869code']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['ypid']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['itemNameYb']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['nationCodeYb']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['drugLb']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['itemYbMemo']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['lmtUsedFlag']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['herbalItfId']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['zcbah']" />
        </a-form-item>
        <a-form-item v-show="false"><a-input v-decorator="['iD']" /></a-form-item>
        <a-form-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择创建时间" v-decorator="['cREATE_DATE']" @change="onChangecREATE_DATE"/>
        </a-form-item>
        <a-form-item label="创建者Id" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入创建者Id" v-decorator="['cREATE_USER_ID']" />
        </a-form-item>
        <a-form-item label="创建者名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入创建者名称" v-decorator="['cREATE_USER_NAME']" />
        </a-form-item>
        <a-form-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择更新时间" v-decorator="['mODIFY_DATE']" @change="onChangemODIFY_DATE"/>
        </a-form-item>
        <a-form-item label="修改者Id" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入修改者Id" v-decorator="['mODIFY_USER_ID']" />
        </a-form-item>
        <a-form-item label="修改者名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入修改者名称" v-decorator="['mODIFY_USER_NAME']" />
        </a-form-item>
        <a-form-item label="删除时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择删除时间" v-decorator="['dELETE_DATE']" @change="onChangedELETE_DATE"/>
        </a-form-item>
        <a-form-item label="删除者ID" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入删除者ID" v-decorator="['dELETE_USER_ID']" />
        </a-form-item>
        <a-form-item label="删除者姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入删除者姓名" v-decorator="['dELETE_USER_NAME']" />
        </a-form-item>
        <a-form-item label="软删除标记" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-switch v-decorator="['iS_DELETED', { valuePropName: 'checked' }]" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import moment from 'moment'
  import {
    DrugPriceListEdit
  } from '@/api/modular/main/DrugPriceListManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        enterDateDateString: '',
        cREATE_DATEDateString: '',
        mODIFY_DATEDateString: '',
        dELETE_DATEDateString: '',
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      moment,
      // 初始化方法
      edit (record) {
        this.visible = true
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              iD: record.iD,
              sysClass: record.sysClass,
              drugId: record.drugId,
              drugCode: record.drugCode,
              drugName: record.drugName,
              toxiProperty: record.toxiProperty,
              drugForm: record.drugForm,
              drugUsage: record.drugUsage,
              drugInputCode: record.drugInputCode,
              drugInputCodeWb: record.drugInputCodeWb,
              drugSpec: record.drugSpec,
              storeUnit: record.storeUnit,
              firmId: record.firmId,
              tradePrice: record.tradePrice,
              retailPrice: record.retailPrice,
              outpUnit: record.outpUnit,
              outpMod: record.outpMod,
              inpUnit: record.inpUnit,
              inpMod: record.inpMod,
              leastPack: record.leastPack,
              leastUnit: record.leastUnit,
              leastDose: record.leastDose,
              classOnOutpRcpt: record.classOnOutpRcpt,
              classOnInpRcpt: record.classOnInpRcpt,
              classOnReckoning: record.classOnReckoning,
              subjCode: record.subjCode,
              classOnMr: record.classOnMr,
              forignCode: record.forignCode,
              feeTypeMask: record.feeTypeMask,
              operator: record.operator,
              performedByCode: record.performedByCode,
              performedByName: record.performedByName,
              remark: record.remark,
              back1: record.back1,
              back2: record.back2,
              inPrice: record.inPrice,
              doseUnit: record.doseUnit,
              siLevel: record.siLevel,
              siCode: record.siCode,
              drugProperty: record.drugProperty,
              prescriptionFlag: record.prescriptionFlag,
              drugLimit: record.drugLimit,
              collisionFlag: record.collisionFlag,
              drugAlias: record.drugAlias,
              drugEng: record.drugEng,
              bidFlag: record.bidFlag,
              execLevel: record.execLevel,
              drugType: record.drugType,
              siRate: record.siRate,
              limitDays: record.limitDays,
              passCode: record.passCode,
              drugType1: record.drugType1,
              drugType2: record.drugType2,
              drugType3: record.drugType3,
              drugType4: record.drugType4,
              drugType5: record.drugType5,
              dosage: record.dosage,
              frequency: record.frequency,
              yh869code: record.yh869code,
              ypid: record.ypid,
              itemNameYb: record.itemNameYb,
              nationCodeYb: record.nationCodeYb,
              drugLb: record.drugLb,
              itemYbMemo: record.itemYbMemo,
              lmtUsedFlag: record.lmtUsedFlag,
              herbalItfId: record.herbalItfId,
              zcbah: record.zcbah,
              cREATE_USER_ID: record.cREATE_USER_ID,
              cREATE_USER_NAME: record.cREATE_USER_NAME,
              mODIFY_USER_ID: record.mODIFY_USER_ID,
              mODIFY_USER_NAME: record.mODIFY_USER_NAME,
              dELETE_USER_ID: record.dELETE_USER_ID,
              dELETE_USER_NAME: record.dELETE_USER_NAME,
              iS_DELETED: record.iS_DELETED
            }
          )
        }, 100)
        this.form.getFieldDecorator('enterDate', { initialValue: moment(record.enterDate, 'YYYY-MM-DD') })
        this.enterDateDateString = moment(record.enterDate).format('YYYY-MM-DD')
        this.form.getFieldDecorator('cREATE_DATE', { initialValue: moment(record.cREATE_DATE, 'YYYY-MM-DD') })
        this.cREATE_DATEDateString = moment(record.cREATE_DATE).format('YYYY-MM-DD')
        this.form.getFieldDecorator('mODIFY_DATE', { initialValue: moment(record.mODIFY_DATE, 'YYYY-MM-DD') })
        this.mODIFY_DATEDateString = moment(record.mODIFY_DATE).format('YYYY-MM-DD')
        this.form.getFieldDecorator('dELETE_DATE', { initialValue: moment(record.dELETE_DATE, 'YYYY-MM-DD') })
        this.dELETE_DATEDateString = moment(record.dELETE_DATE).format('YYYY-MM-DD')
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            values.enterDate = this.enterDateDateString
            values.cREATE_DATE = this.cREATE_DATEDateString
            values.mODIFY_DATE = this.mODIFY_DATEDateString
            values.dELETE_DATE = this.dELETE_DATEDateString
            DrugPriceListEdit(values).then((res) => {
              if (res.success) {
                this.$message.success('编辑成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      onChangeenterDate(date, dateString) {
        this.enterDateDateString = dateString
      },
      onChangecREATE_DATE(date, dateString) {
        this.cREATE_DATEDateString = dateString
      },
      onChangemODIFY_DATE(date, dateString) {
        this.mODIFY_DATEDateString = dateString
      },
      onChangedELETE_DATE(date, dateString) {
        this.dELETE_DATEDateString = dateString
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
